﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF.Caching.Impl
{
    /// <summary>
    /// Implémente un cache statique
    /// </summary>
    public class StaticCache : IForeverCache, ICache, IPerRequestCache, IPerSessionCache
    {
        readonly static Dictionary<string, object> cache = new Dictionary<string, object>();

        #region ICache Members

        readonly object lockInstance = new object();

        public object this[string key]
        {
            get
            {
                lock (lockInstance)
                {
                    if (cache.ContainsKey(key)) return cache[key];
                }
                return null;
            }
            set
            {
                lock (lockInstance)
                {
                    cache[key] = value;
                }
            }
        }

        public bool Contains(string key)
        {
            return cache.ContainsKey(key);
        }

        #endregion
    }
}
